/**
 * 更新图层的渲染属性
 * @param mapboxInstance
 * @param layerId
 * @param paint
 */
export function updateLayerPaint(
  mapboxInstance: any,
  layerId: string,
  paint: any
) {
  Object.keys(paint).forEach((name: string) => {
    mapboxInstance.setPaintProperty(layerId, name, paint[name])
  })
}

/**
 * 更新图层的布局属性
 * @param mapboxInstance
 * @param layerId
 * @param layout
 */
export function updateLayerLayout(
  mapboxInstance: any,
  layerId: string,
  layout: any
) {
  Object.keys(layout).forEach((name: string) => {
    mapboxInstance.setLayoutProperty(layerId, name, layout[name])
  })
}

/**
 * 更新图层的 过滤器
 * @param mapboxInstance
 * @param layerId
 * @param filter
 */
export function updateLayerFilter(
  mapboxInstance: any,
  layerId: string,
  filter: any[]
) {
  mapboxInstance.setFilter(layerId, filter)
}

/**
 * 更新图层的 过滤器, 渲染, 布局
 * @param mapboxInstance
 * @param layerId
 * @param {filter, paint, layout}, 过滤器, 渲染, 布局
 */
export function updateLayerStyles(
  mapboxInstance: any,
  layerId: string,
  { filter, paint, layout }: any
) {
  if (filter) {
    updateLayerFilter(mapboxInstance, layerId, filter)
  }
  if (layout) {
    updateLayerLayout(mapboxInstance, layerId, layout)
  }
  if (paint) {
    updateLayerPaint(mapboxInstance, layerId, paint)
  }
}
